﻿Imports System.Data.SqlClient

Public Class Annuaire
    Public Id As Integer
    Public nomComp As String
    Public Adress As String
    Public occupation As String
    Public email As String
    Public Remarque As String

    'Les constructeur ---------------------------

    Sub New(ByVal Id As Integer, ByVal nomComp As String, ByVal Adress As String, ByVal occupation As String, ByVal email As String, ByVal Remarque As String)
        Me.Id = Id
        Me.nomComp = nomComp
        Me.Adress = Adress
        Me.occupation = occupation
        Me.email = email
        Me.Remarque = Remarque
    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.nomComp = enregistrement.Item(1)
        Me.email = enregistrement.Item(2)
        Me.Adress = enregistrement.Item(3)
        Me.occupation = enregistrement.Item(4)
        Me.Remarque = enregistrement.Item(5)
    End Sub

    Sub New()

    End Sub


    Public list_phone As New ArrayList



    Public Sub remplir_List_list_phone()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where id_Annuaire =" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)

        Next
        Partager.close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where type ='" & type & "' and Id_Annuaire=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Annuaire) values (@Num,@Type,@Id_Annuaire)", Partager.con)

        cmd.Parameters.Add("@Id_Annuaire", SqlDbType.VarChar).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



        Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        Me.remplir_List_list_phone()

    End Sub


End Class
